<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>权限管理页面</title>
    <!-- Bootstrap core CSS -->
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet">
    <link th:href="@{/css/bootstrap-grid.css}" rel="stylesheet">
    <link th:href="@{/css/bootstrap-reboot.css}" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/limonte-sweetalert2/6.6.2/sweetalert2.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link th:href="@{/css/dashboard.css}" rel="stylesheet">
    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .chartjs-render-monitor {
            -webkit-animation: chartjs-render-animation 0.001s;
            animation: chartjs-render-animation 0.001s;
        }

        #searchButton{
            margin-left: 20px;
            width: 100px;
            padding: 0 20px;
            height: 30px;
            border: 1px solid #7ba92c;
            border-radius: 4px;
            color: #fff;
            font-weight: bold;
            background:#87c212;
        }
    </style>
</head>

<body>
<!--顶部导航栏-->
<div th:replace="~{commons/commons::topbar}"></div>

<div class="container-fluid">
    <div class="row">
        <!--将侧边栏抽取为公共部分-->
        <div th:replace="~{commons/commons::sidebar(active='role/list.html')}"></div>

        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">

            <span style="float: right"><a class="btn btn-sm btn-success" th:href="@{/role/roleAdd}">添加职位</a></span>

            <div class="table-responsive">
                <table class="table table-striped table-sm table-bordered" style="width: 100%">
                    <thead>
                    <tr>
                        <th class="text-center">职位编码</th>
                        <th class="text-center">职位名称</th>
                        <th class="text-center">创建日期</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="role:${roleList}">
                        <input type="hidden" class="roleId" name="id" th:value="*{role.getId()}">
                        <td class="text-center" th:text="*{role.getRoleCode()}"></td>
                        <td class="text-center" th:text="*{role.getRoleName()}"></td>
                        <td class="text-center" th:text="*{#dates.format(role.getCreationDate(),'yyyy-MM-dd')}"></td>
                        <td class="text-center">
                            <a class="btn btn-sm btn-info" th:href="@{/role/roleView/{id}(id=${role.id})}">查看</a>
                            <a class="btn btn-sm btn-danger del" th:attr="roleId = ${role.id}">删除</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </main>
    </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->

<script type="text/javascript" th:src="@{/js/jquery-3.2.1.min.js}"></script>
<script type="text/javascript" th:src="@{/js/popper.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/limonte-sweetalert2/6.6.2/sweetalert2.min.js"></script>

<!--删除按钮-->
<script type="text/javascript" th:inline="javascript">

    $('.del').on("click", function () {
        //获取当前标签对象
        var $tr =$(this).parent().parent();
        var code=$(this).parent().parent().find(".roleId").val();
        swal({
            title: "确定删除吗？",
            text: "如果确定将不能恢复这条数据！",
            type: "warning",
            showCancelButton: true,
            confirmButtonText: "确定",
            cancelButtonText: "取消",   //修改cancel显示的
            showLoaderOnConfirm: true  //加载等待时间的显示页面
        }).then(function () {
            $.ajax({
                type: 'GET',
                url: '/zjn/role/roleDelete',
                data: {'code': code},
                dataType: 'json',
                async: false,
                success: function (data) {  // 后端发字典过来 前端不需要你手动转 会自动帮你转换成js自定义对象
                    /*console.log(data.code);*/
                    if (data.code == "success") {
                        // 通过DOM操作 实时改变页面
                        // 将被点击的删除按钮所在的那一行直接从DOM树中删掉
                        $tr.remove();
                        swal(
                            '删除成功！',
                            '该条数据已被成功删除。',
                            'success'
                        ).then(function () {
                            window.location.reload()  //刷新页面
                        });
                    } else if (data.code == "error") {
                        swal('发生了未知的错误', '估计是有bug了', 'info');
                    } else if (data.code == "exist") {
                        swal('删除错误！','仍有员工处于该职位，请先修改员工职位','error');
                    }
                },
                error: function () {
                    swal("后台出错", "请重新执行该操作", "error");
                }
            });
        }, function(dismiss) {
            // dismiss的值可以是'cancel', 'overlay',
            // 'close', 'timer'
            if (dismiss === 'cancel') {
                swal(
                    '已取消！',
                    '你的数据是安全的:)',
                    'info'
                );
            }
        })
    });

</script>

<!-- Icons -->
<script type="text/javascript" th:src="@{/js/feather.min.js}"></script>
<script>
    feather.replace()
</script>

<!-- Graphs -->
<script type="text/javascript" th:src="@{/js/Chart.min.js}"></script>

<script>
    var ctx = document.getElementById("myChart");
    var myChart = new Chart(ctx, {
        type: 'line',
        data: {
            labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
            datasets: [{
                data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
                lineTension: 0,
                backgroundColor: 'transparent',
                borderColor: '#007bff',
                borderWidth: 4,
                pointBackgroundColor: '#007bff'
            }]
        },
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: false
                    }
                }]
            },
            legend: {
                display: false,
            }
        }
    });
</script>

</body>

</html>